/*
 * This file is part of Shopping Lists Organizer software
 *
 * Copyright (C) 2011 Denis Kvita <dkvita@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include <QtGui>
#include <QtSql>

#include "calendar.h"

Calendar::Calendar(QWidget *parent) :
	QCalendarWidget(parent)
{
	setVerticalHeaderFormat(QCalendarWidget::NoVerticalHeader);
}

void Calendar::paintCell( QPainter *painter, const QRect &rect, const QDate &date) const
{
	painter->save();
	QCalendarWidget::paintCell(painter,rect,date);
	QSqlDatabase dbc= QSqlDatabase::database("CN");
	QSqlQuery q(dbc);
	q.prepare(QString("SELECT pDate FROM purchase WHERE pDate=:D LIMIT 1"));
	q.bindValue(":D",date.toString("yyyy-MM-dd"));
	if(q.exec() && q.next()){
		painter->setBrush(QBrush(QColor(0,255,0,50)));
		painter->setPen(Qt::NoPen);
		QRect r(rect.left()+1, rect.top()+1, rect.width()-1, rect.height()-1);
		painter->drawRect(r);
	}
	painter->restore();
}
